package pers.sloera.leetcode.editor.cn;

import java.util.Arrays;

/**
 * 奇数值单元格的数目
 *
 * @author sloera
 * @date 2022-07-12 22:40:00
 */
class CellsWithOddValuesInAMatrix {
    public static void main(String[] args) {
        Solution solution = new CellsWithOddValuesInAMatrix().new Solution();
        // System.out.println(solution.oddCells(2, 3, new int[][]{{0, 1}, {1, 1}}));
        System.out.println(solution.oddCells(2, 2, new int[][]{{1, 1}, {0, 0}}));
    }

    // leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int oddCells(int m, int n, int[][] indices) {
            int[][] grid = new int[m][n];
            for (int[] indice : indices) {
                for (int i = 0; i < grid[0].length; i++) {
                    grid[indice[0]][i] = grid[indice[0]][i] + 1;
                }
                for (int i = 0; i < grid.length; i++) {
                    grid[i][indice[1]] = grid[i][indice[1]] + 1;
                }
            }
            return (int) Arrays.stream(grid).mapToLong(cell -> Arrays.stream(cell).map(x -> x % 2 == 0 ? 0 : 1).sum()).sum();
        }
    }
    // leetcode submit region end(Prohibit modification and deletion)

}
